<template>
  <div class="list">
      <van-grid :gutter="10">
        <template #default>
          <div class="list-content">
            <!-- 标题 -->
            <div class="list-content-title">
              <h4>豆瓣周榜</h4>
              <h3>口碑电影</h3>
            </div>
            <!-- 内容列表 -->
            <div class="list-content-list">
              <div
                class="list-content-list-item"
                v-for="item in weekly.slice(0,3)"
                :key="item.rank"
              >
                <div>
                  <span class="item-title">{{item.rank}}.{{item.subject.title}}</span>
                  <span class="item-rate">{{ item.subject.rating.average}}</span>
                </div>
              </div>
            </div>
              <router-link class="list-more" :to="{name: 'DoubanList',params: {title: '豆瓣周榜'}}" style="color: #eee">
                更多<van-icon name="arrow" />
              </router-link>
          </div>
          <div class="list-content">
            <!-- 标题 -->
            <div class="list-content-title">
              <h4>TOP250</h4>
              <h3>豆瓣电影</h3>
            </div>
            <!-- 内容列表 -->
            <div class="list-content-list">
              <div
                class="list-content-list-item"
                v-for="(item, index) in top.slice(0,5)"
                :key="item.id"
              >
                <div>
                  <span class="item-title">{{ index+1 }}.{{item.title}}</span>
                  <span class="item-rate">{{ item.rating.average }}</span>
                </div>
              </div>
            </div>
              <router-link class="list-more" :to="{name: 'DoubanList',params: {title: 'TOP250'}}" style="color: #eee">
                更多<van-icon name="arrow" />
              </router-link>
          </div>
        </template>
      </van-grid>
    </div>
</template>

<script>
import { getWeekly, getTop250 } from '@/api/home'

export default {
  name: '',
  data () {
    return {
      weekly: [], // 周榜
      top: [], // top250
      start: 0,
      count: 5,
    }
  },
  methods: {
    updateData () {},
  },
  computed: {},
  components: {},
  created () {
    getWeekly()
      .then((res) => {
        console.log(res)
        this.weekly = res.subjects
        console.log('this.weekly', this.weekly)
      })
      .catch(console.log)
    getTop250(this.start, this.count)
      .then((res) => {
        // console.log(res)
        this.top = res.subjects
        // console.log(this.title)
        // console.log('this.top', this.top)
      })
      .catch(console.log)
  },
}
</script>

<style lang='less' scoped>
.list {
  width: 100vw;
  box-sizing: border-box;
  color: #edeceb;
  padding: 0 5px;
  /deep/ .van-grid {
    padding-left: 0 !important;
  }
  .list-content {
    width: 100vw;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    background-color: #4c3b33;
    padding: 10px 5px;
    border-radius: 10px;
    margin: 5px 0;
    .list-content-title {
      text-align: center;
      * {
        margin: 0;
        padding: 0;
      }
      h4 {
        color: #bbb5b1;
      }
    }
    .list-content-list {
      flex: 1;
      margin: 5px 20px;
      .list-content-list-item {
        display: flex;
        flex: 1;
        margin: 5px 0;
        .item-rate {
          color: #fd9800;
          margin-left: 10px;
        }
      }
    }
  }
}
</style>
